package com.yanqu.road.server.cmd.activity.busyfarming;

import com.yanqu.road.pb.activity.BusyFarmingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.busyfarming.BusyFarmingModule;
import com.yanqu.road.server.manger.activity.busyfarming.BusyFarmingMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_BUSY_FARMING_SELLING_FRUIT,desc = "卖水果")
public class BusyFarmingSellingFruitCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(BusyFarmingMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!BusyFarmingMgr.activityInTime()){
            ret = GameErrorCode.E_BUSY_FARMING_ACTIVITY_NO_IN_TIME;
            return;
        }

        ret = player.getModule(BusyFarmingModule.class).sellingFruit();
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            BusyFarmingProto.BusyFarmingSellingFruitRespMsg.Builder respMsg = BusyFarmingProto.BusyFarmingSellingFruitRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_BUSY_FARMING_SELLING_FRUIT, respMsg);
        }
    }
}
